<!doctype html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"   content="width=device-width, initial-scale=1">
    <title>返回JSON</title>
    {% include 'index/public/style.html' %}
</head>
<body>
<div class="container ">
    {% include 'index/public/head.html' %}
    {% include 'index/public/nav.html' %}

    <div class="box">
        <h1 class="title">返回JSON</h1>
        {{request.host_url}}api/index/<br>
        {{request.host_url}}api/index/index<br>
        {{request.host_url}}api/index/list<br>
        {{request.host_url}}api/index/show<br>

        <button id="test1" >TEST_list</button>
        <button id="test2" >TEST_show</button>
        <div id="list">

        </div>
    </div>
    {% include 'index/public/foot.html' %}
    <script>
    $(document).ready(function() {
        $("#test1").click(function(){
            $.get("{{request.host_url}}{{get_url('api.index.list')}}",function(data){
                console.log(data)
                for (var i = 0; i < data.length; i++) {
                    var obj = data[i];
                    $('#list').append('<p>'+obj.id+filterXSS(obj.title)+'<p>')
                }

            })
         })
         $("#test2").click(function(){
            $.get("{{request.host_url}}{{get_url('api.index.show')}}",function(data){
                console.log(data)
                alert(data.content)
            })
         })

    });

    function filterXSS(str) {
      // 移除或转义特殊字符
      return str.replace(/</g, '&lt;')
                .replace(/>/g, '&gt;')
                .replace(/"/g, '&quot;')
                .replace(/'/g, '&#039;');
    }
    </script>
</div>
</body>
</html>
